export default {
    state: null,
    subscriptions:{
        syscLocalstroage({dispatch}){
            var loginId = localStorage.getItem("loginId")
            if (loginId){
                dispatch({ type: "setLoginUser", payload: loginId})
            }
        }
    },
    reducers: {
        setLoginUser(state, action) {
            return action.payload
        }
    },
    effects: {
        *login({ payload }, { put }) {
            const { loginId, loginPwd } = payload
            if (loginId === "admin" && loginPwd === "123123") {
                yield put({ type: "setLoginUser", payload: loginId })
                localStorage.setItem("loginId", loginId)
                return true
            }
            return false
        },
        *loginOut(action, { put }) {
            localStorage.removeItem("loginId")
            yield put({ type: "setLoginUser", payload: null })
        }
    }
}